package com.common.base;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.common.R;
import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;


/**
 * Created by Administrator on 2017/7/26.
 */

public abstract class BaseWebViewActivity extends BaseMvpActivity {

    public WebView webView;

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {

        return R.layout.activity_base_webview;
    }

    @Override
    protected void onViewCreated() {
        webView = (WebView) findViewById(R
                .id.webview);
    }

    @Override
    protected void doLogicFunc() {
        dolocgicFunc();
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
//                view.loadUrl(url);
//                return true;
                if (url.startsWith("tel:")) {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else
                    view.loadUrl(url);
                return true;
            }
        });

    }

//        webView.loadUrl();


    public abstract void dolocgicFunc();
}
